using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;

public class DetailPanel : BasePanel
{
    private Transform UIStars;
    private Transform UIDescription;
    private Transform UIIcon;
    private Transform UITitle;
    private Transform UILevelText;
    private Transform UISkillDescription;

    private PackageLocalItem _packageLocalItem;
    private PackageTableItem _packageTableItem;


    protected override void Awake()
    {
        base.Awake();
        InitUIName();
    }

    private void Start()
    {
        RefreshUI(GameManager.Instance.GetPackageLocalItems()[0]);
    }

    private void InitUIName()
    {
        UIStars = transform.Find("Center/Stars");
        UIDescription = transform.Find("Center/Description");
        UIIcon = transform.Find("Center/Icon");
        UITitle = transform.Find("Top/WeaponText");
        UILevelText = transform.Find("Bottom/LevelPnl/LevelText");
        UISkillDescription = transform.Find("Bottom/Description");
    }

    public void RefreshUI(PackageLocalItem packageLocalItem)
    {
        _packageLocalItem = packageLocalItem;
        _packageTableItem = GameManager.Instance.GetPackageTableItemByid(packageLocalItem.id);
        UIDescription.GetComponent<Text>().text = _packageTableItem.description;
        //等级
        UILevelText.GetComponent<Text>().text = string.Format("Lv.{0}/40", packageLocalItem.level);
        //星级
        RefreshStar();

        //图标
        Image image = UIIcon.GetComponent<Image>();
        image.sprite = Resources.Load<Sprite>(_packageTableItem.imagePath);
        UITitle.GetComponent<Text>().text = _packageTableItem.name;
        UISkillDescription.GetComponent<Text>().text = _packageTableItem.skillDescription;
    }

    private void RefreshStar()
    {
        for (int i = 0; i < 5; i++)
        {
            UIStars.GetChild(i).gameObject.SetActive(true);
        }

        for (int i = 0; i < 5 - _packageTableItem.star; i++)
        {
            UIStars.GetChild(i).gameObject.SetActive(false);
        }
    }
}